package study.alibaba.sentinel.controller._1_flow;

import com.alibaba.csp.sentinel.Entry;
import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import study.eggs.result.Result;
import study.eggs.result.Results;

import java.util.Map;

@Slf4j
@RestController
public class _01_FlowController {

    @RequestMapping("/flow1")
    public Result echo() {
        Entry entry = null;
        try {
            entry = SphU.entry("Hello"); //限流入口
        } catch (BlockException ex) {

        } finally {
            if (entry != null) {
                entry.exit(); //限流出口
            }
        }
        Map<String, Object> data = Maps.newHashMap();
        data.put("msg", "flow1 flow1 flow1");
        return Results.ok(data);
    }
}
